package com.qiang.test.entry;


import com.qiang.test.domain.Manager;
import com.qiang.test.domain.Subway;
import com.qiang.test.service.Service;

import java.util.ArrayList;
import java.util.Scanner;

public class Demo {
    Service s = new Service();
    Scanner scan = new Scanner(System.in);
    ArrayList<Manager> mList = s.managerLoad();
    ArrayList<Subway> sList = s.subwayInput();

    public static void main(String[] args) {
        Demo demo = new Demo();
        while (true) {
            if (demo.login()) {
                break;
            }
            System.out.println("工号或姓名错误!");
        }
        while (true) {
            System.out.println("\n1.查看地铁站");
            System.out.println("2.添加地铁站");
            System.out.print("请选择:");
            switch (demo.scan.next()) {
                case "1":
                    demo.listSubway();
                    break;
                case "2":
                    demo.addSubway();
                    break;
                default:
                    System.out.println("输入错误,重新输入!");
            }
        }
    }

    public void addSubway() {
        System.out.print("请输入地铁站编号:");
        String id = scan.next();
        System.out.print("请输入地铁站名称:");
        String name = scan.next();
        System.out.print("请输入地铁站所属路线:");
        String way = scan.next();
        sList.add(new Subway(id, name, way));
        s.subwayOutput(sList);
    }

    public void listSubway() {
        if (sList.size() == 0) {
            System.out.println("还没有地铁站信息!");
        }
        System.out.println("编号\t名称\t路线");
        sList.forEach(subway -> System.out.println(subway));
    }

    public boolean login() {
        System.out.print("请输入工号:");
        String id = scan.next();
        System.out.print("请输入姓名:");
        String name = scan.next();
        for (Manager manager : mList) {
            if (name.equals(manager.getName())) {
                if (id.equals(manager.getId())) {
                    return true;
                }
            }
        }
        return false;
    }
}
